package tr.edu.metu.is.mega.client.course.activity;

import tr.edu.metu.is.mega.client.core.EditDialog;
import tr.edu.metu.is.mega.client.widgets.MegaTextField;
import tr.edu.metu.is.mega.common.dto.UserDTO;

import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.layout.FormData;

/**
 * Dialog to edit users.
 */
public class ExportCalendarDialog extends EditDialog<UserDTO> {

    private MegaTextField textFieldEmail;

    private MegaTextField textFieldPassword;

    /**
     * Default constructor.
     */
    public ExportCalendarDialog() {
        super(UserDTO.class.getName());
        setHeading("Login info");
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void initForm(FormPanel parent, Object... params) {

        Label label = new Label("Enter your e-mail and password to authenticate Google, we will never store information provided.");
        parent.add(label, new FormData("100%"));

        textFieldEmail = new MegaTextField(UserDTO.FIELD_EMAIL);
        textFieldEmail.setFieldLabel("E-Mail");
        textFieldEmail.setValue("mega@ekremkenter.com");
        parent.add(textFieldEmail, new FormData("96%"));

        textFieldPassword = new MegaTextField(UserDTO.FIELD_PASSWORD);
        textFieldPassword.setFieldLabel("Password");
        textFieldPassword.setValue("megamail");
        textFieldPassword.setPassword(true);
        parent.add(textFieldPassword, new FormData("96%"));

        setHeight(200);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected UserDTO guiToDTO() {
        UserDTO dto = new UserDTO();
        dto.setEmail(textFieldEmail.getValue());
        dto.setPassword(textFieldPassword.getValue());
        return dto;
    }
}
